from django.shortcuts import render_to_response
from django.http import HttpResponseServerError, HttpResponse, HttpResponseRedirect


from django.views.decorators.csrf import csrf_exempt
from django.core.context_processors import csrf
from cart.forms import ProductForm
from formwizard.views import CookieWizardView

def home(request):
    return render_to_response('index.html', {'poll': 123})

@csrf_exempt
def error500(request):
    return HttpResponseServerError('bad bad 500')

def product(request):
    if request.method == 'POST':
        form = ProductForm(request.POST)
        if form.is_valid():
            # process form.cleaned_data
            return HttpResponse('good') 
    else:
        form = ProductForm(initial={'sku': 'y'})

    context = {'form': form}
    context.update(csrf(request))
    return render_to_response('product.html', context)

def done(request):
    return render_to_response('done.html', {})

class GavinWizard(CookieWizardView):

    def done(self, form_list, **kwargs):
        self.process_form_data(form_list)
        return HttpResponseRedirect('/flow/done/')

    def process_form_data(self, form_list):
        pass

    def process_step(self, form):
        print 'process_step ' + str(form)
        print 'process_step hasattr(request) ' + str(hasattr(self, 'request'))
        return self.get_form_step_data(form)
